﻿<%@ WebHandler Language="C#" Class="ShowListIntent" %>

using System;
using System.Web;
using System.Text;
using System.Data;
using System.Collections.Generic;
using Chenxin.Lib.Utility;
using Chenxin.Lib.Business;
using Chenxin.Lib.Business.BLL;
using Chenxin.Lib.Hr;

public class ShowListIntent : AjaxHandlerBase
{
    
   /// <summary>
    /// 基本权限项
    /// </summary>
    public ShowListIntent()
    {
        //意向书查询
        htTypePermit.Add("searchletterofintent", Constants.Permit_SearchLetterOfIntent);
        //意向书编号发放
        htTypePermit.Add("issue", Constants.Permit_LetterOfIntentIssue);
        //意向书生效
        htTypePermit.Add("effective", Constants.Permit_Intent_Effective);
        //意向书失效
        htTypePermit.Add("uesless", Constants.Permit_Intent_UnEffective);
        //意向书遗失
        htTypePermit.Add("lost", Constants.Permit_Intent_Lost);
        //意向书作废
        htTypePermit.Add("delete", Constants.Permit_Intent_Cancel);
        //法务部回收
        htTypePermit.Add("recallbyfw", Constants.Permit_Intent_RecallByFW);
        //门店回收
        htTypePermit.Add("recallbymd", Constants.Permit_Intent_RecallByMD);
        //添加意向金
        htTypePermit.Add("addmoney", Constants.Permit_Intent_AddMoney);
        //变更业务员
        htTypePermit.Add("chgemp", Constants.Permit_Intent_ChangeUser);
        //意向书下发
        htTypePermit.Add("letterofintentdeliver", Constants.Permit_LetterOfIntentDeliver);
        //意向金转移
        htTypePermit.Add("payadd", Constants.Permit_Money_Move);
        //意向书资料录入
        htTypePermit.Add("inputinfo", Constants.Permit_Intent_Input);
        //意向书资料编辑
        htTypePermit.Add("editinfo", Constants.Permit_Intent_Edit);
        //意向书领用
        htTypePermit.Add("getletter", Constants.Permit_LetterOfIntentReceive);
        //意向书收款
        htTypePermit.Add("billadd", Constants.Permit_Intent_BillAdd);
        //导出
        htTypePermit.Add("export", Constants.Permit_Intent_Export);      
    }
    
    override public void RequestProcess(HttpContext context)
    {
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string strOp = context.Request["op"];
        string strResponse = "";
        switch (strOp.ToLower())
        {
            //获取实体
            case "getmodel":
                strResponse = GetModel(context);
                break;
                //获取房源信息
            case "gethouse":
                strResponse = getHouse(context);
                break;
            //获取意向编号
            case "getcode":
                strResponse = GetCode(context);
                break;
            //查询
            case "search":
                strResponse = Search(context);
                break;
            //发放
            case "issue":
                strResponse = Issue(context);
                break;
            //意向书下发
            case "letterofintentdeliver":
                strResponse = Deliver(context);
                break;
            case "getdeliverlist":
                strResponse = GetDeliverList(context);
                break;
            //领用
            case "getletter":
                strResponse = GetLetter(context);
                break;
            //录入
            case "inputinfo":
                strResponse = InputInfo(context);
                break;
            //未生效
            case "uesless":
                strResponse = UnEffectiveInfo(context);
                break;
            //作废
            case "delete":
                strResponse = CancelInfo(context);
                break;
            //遗失
            case "lost":
                strResponse = LoseInfo(context);
                break;
            //法务回收
            case "recallbyfw":
                strResponse = RecallByFW(context);
                break;
            //门店回收
            case "recallbymd":
                strResponse = RecallByMD(context);
                break;
            //添加意向金
            case "addmoney":
                strResponse = AddMoney(context);
                break;
            //变更业务员
            case "chgemp" :
                strResponse = ChangeUser(context);
                break;
            //开单
            case "billadd":
                strResponse = BillAdd(context);
                break;
            //生效
            case "effective":
                strResponse = Effective(context);
                break;
            //意向金转移
            case "payadd":
                strResponse = PayAdd(context);
                break;
            case "editinfo":
                strResponse = EditInfo(context);
                break;
            default:
                break;
        }
        context.Response.Write(strResponse);
    }

    //意向书资料编辑
    //2010-9-17
    //tianno
    private string EditInfo(HttpContext context)
    {
        try
        {
            //意向书信息
            string IntentionInfo = context.Request.Params["model"];

            //意向书信息格式化
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention =
                (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(IntentionInfo,
                        typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entOld = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entIntention.IntentionId);

            //更新数据
            entOld.HouseCode = entIntention.HouseCode;
            entOld.HouseAddress = entIntention.HouseAddress;
            entOld.HouseId = entIntention.HouseId;
            entOld.Region = entIntention.Region;
            entOld.TotalPrice = entIntention.TotalPrice;
            entOld.CustomerName_Buy = entIntention.CustomerName_Buy;
            entOld.CustomerName_Sale = entIntention.CustomerName_Sale;
            entOld.DeliverTo = entIntention.DeliverTo;
            entOld.LastContractDate = entIntention.LastContractDate;
            entOld.LastDeliverMoneyDate = entIntention.LastDeliverMoneyDate;
            entOld.UpdateEmp = CurrentUserInfo.UserName;
            entOld.UpdateEmpId = CurrentUserInfo.UserId;
            entOld.UpdateTime = DateTime.Now;
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(entOld);

            string text = CurrentUserInfo.UserName + "：意向书资料编辑。意向书编号：" + entIntention.IntentionCode;
            AddLog(text, BusinessType.BusinessTypeComboList()["OprType_EditIntention"].ToString());
            
            return retExecResult(Constants.ExecResult.Succ, "意向书资料修改成功！", "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    
    
    //意向金转移
    //2010-9-16
    //tianno
    private string PayAdd(HttpContext context)
    {
        try
        {
            //开单信息
            string billgeted = context.Request.Params["model"];
            string paymoney = context.Request.Params["PayMoney"];

            //开单业务类
            Chenxin.Lib.Business.BLL.t_Intention_BillGetedInfo bllBillGeted = new Chenxin.Lib.Business.BLL.t_Intention_BillGetedInfo();


            t_Intention_BaseInfo bllIntent = new t_Intention_BaseInfo();

            //开单信息
            Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo entBillGeted =
                (Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo)JsonHelp.Convert2Entity(billgeted,
                        typeof(Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo));
            entBillGeted.GetedMoney = decimal.Parse(paymoney);

            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntent = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entBillGeted.IntentionId);
            entBillGeted = CompleteBillGeted(entBillGeted,0);

            //更新意向书相关信息
            entIntent.UpdateTime = DateTime.Now;
            entIntent.UpdateEmp = CurrentUserInfo.UserName;
            entIntent.UpdateEmpId = CurrentUserInfo.UserId;
            if (entIntent.DeliveredMoney == null)
                entIntent.DeliveredMoney = 0;
            entIntent.DeliveredMoney += decimal.Parse(paymoney);
            

            //开单信息录入
            bllBillGeted.Add(entBillGeted);
            bllIntent.Update(entIntent);

            //****************获取打印信息****************************
            Chenxin.Lib.Business.Entity.v_PrintMoneyInfo model = Chenxin.Lib.Business.DAL.v_PrintMoneyInfo.GetModel(entBillGeted.BillId);
            if (model == null) return retExecResult(Constants.ExecResult.Error, "获取开单信息失败，请联系管理员！", "");

            model.PrintTime = DateTime.Now.ToShortDateString();
            string str = "";
            Chenxin.Lib.Utility.InitialHelper.TranslateNumberToChinese(model.GetedMoney.ToString(), out str);
            model.GetedMoneyBig = str;

            string strSql = "IntentionId='" + entBillGeted.BillId + "'";

            List<Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo> list = Chenxin.Lib.Business.DAL.t_Intention_BillPrintInfo.GetListArray(strSql);
            model.PrintCount = list.Count + 1;

            return string.Format("{{success:1,msg:'意向金转移成功！',data:{{model:{0}}}}}", JsonHelp.Convert2Json(model));
            //**********************************************************
            
            //return retExecResult(Constants.ExecResult.Succ, "意向金转移成功！", "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    
    //意向书生效
    //2010-9-16
    //tianno
    private string Effective(HttpContext context)
    {
        try
        {
            string modelid = context.Request.Params["modelid"];
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(new Guid(modelid));
            baseinfo.Status = 10;
            baseinfo.UpdateEmp = CurrentUserInfo.UserName;
            baseinfo.UpdateEmpId = CurrentUserInfo.UserId;
            baseinfo.UpdateTime = DateTime.Now;
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(baseinfo);
            
            return retExecResult(Constants.ExecResult.Succ, "生效成功！", "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    
    //获取下发意向书
    //2010-9-7
    //tianno
    private string GetDeliverList(HttpContext context)
    {
        try
        {
            string idlist = context.Request.Params["idlist"];
            
            //条件
            string strWhere = string.Format("IntentionId in ('{0}')",idlist.Replace(",","','"));
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数
            //欲选择字段列表 
            string FieldList = "*";
            //子查询欲选择字段列表
            string TableFieldList = "*";
            //所要查询的表名
            string TableName = "t_Intention_BaseInfo ";
            //根据sql执行查询
            DataSet ds = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetList(strPageIndex, strPageSize, "CreateDate", TableName, strWhere, FieldList, TableFieldList, true);

            return string.Format("{{success:1,msg:'',data:{{count:{0},{1}}}}}", Convert.ToInt32(ds.Tables[1].Rows[0][0]), JsonHelp.Convert2Json(ds.Tables[0]));
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    //获取房源信息
    private string getHouse(HttpContext context)
    {
        try
        {
            //从请求中获得房源Code
            string HouseCode = context.Request.Params["housecode"];
            
            //从请求中获得意向Code
            string[] IntentionCode = context.Request.Params["intentioncode"].Split('-');

            //获取相应房源信息
            Chenxin.Lib.House.Entity.House_BaseInfo entHouseInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetHouseInfoEntityByCode(HouseCode);
            //转成Json，发回客户端
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention = new Chenxin.Lib.Business.Entity.t_Intention_BaseInfo();
            if (entHouseInfo == null)
            {
                return retExecResult(Constants.ExecResult.Error, "没有相应的房源信息！", "");
            }
            else
            {
                entIntention.HouseCode = entHouseInfo.HouseCode;
                entIntention.HouseAddress = entHouseInfo.DetailAddress;
                entIntention.HouseId = entHouseInfo.HouseId;
                entIntention.Region = entHouseInfo.Region;
                entIntention.CustomerName_Sale = entHouseInfo.CustomerName;
            }
            
            if (IntentionCode[1].Equals("MY"))
            {
                entIntention.TotalPrice = entHouseInfo.SalePrice_T;
            }
            else if (IntentionCode[1].Equals("ZY"))
            {
                entIntention.TotalPrice = entHouseInfo.RentPrice;
            }
            
            return retExecResult(Constants.ExecResult.Succ, "获取信息成功！", entIntention);
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    //意向书下发
    //2010-9-7
    //tianno
    private string Deliver(HttpContext context)
    {
        try
        {
            string idlist = context.Request.Params["idlist"];
            string cityid = context.Request.Params["cityid"];
            string city = context.Request.Params["city"];
            string companyid = context.Request.Params["companyid"];
            string company = context.Request.Params["company"];
            string depid = context.Request.Params["departid"];
            string dep = context.Request.Params["depart"];
            string empid = context.Request.Params["userid"];
            string emp = context.Request.Params["user"];
            
            string[] list = idlist.Split(',');
            emp = emp.Remove(emp.IndexOf("("));

            string failid = "";
            string codelist = "";
            foreach (string s in list)
            {
                Chenxin.Lib.Business.Entity.t_Intention_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(new Guid(s));

                if (baseinfo.Status != -200)
                {
                    failid += baseinfo.IntentionCode + ",";
                }
                else
                {
                    //下发日志
                    Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs logs = new Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs();
                    logs.RecordId = Guid.NewGuid();
                    logs.IntentionId = baseinfo.IntentionId;
                    logs.IntentionCode = baseinfo.IntentionCode;
                    logs.DeliverTime = DateTime.Now;
                    logs.DeliverCity = baseinfo.BelongCityName;
                    logs.DeliverCityId = baseinfo.BelongCityId;
                    logs.DeliverCompany = baseinfo.BelongCompany;
                    logs.DeliverCompanyId = baseinfo.BelongCompanyId;
                    logs.DeliverDepart = baseinfo.BelongDepart;
                    logs.DeliverDepartId = baseinfo.BelongDepartId;
                    logs.DeliverEmp = baseinfo.BelongEmp;
                    logs.DeliverEmpId = baseinfo.BelongEmpId;
                    logs.ReceiveCity = city;
                    logs.ReceiveCityId = new Guid(cityid);
                    logs.ReceiveCompany = company;
                    logs.ReceiveCompanyId = new Guid(companyid);
                    logs.ReceiveDepart = dep;
                    logs.ReceiveDepartId = new Guid(depid);
                    logs.ReceiveEmp = emp;
                    logs.ReceiveEmpId = new Guid(empid);
                    logs.Status = 10;
                    Chenxin.Lib.Business.DAL.t_Intention_DeliverLogs.Add(logs);
                    
                    //意向书
                    codelist += baseinfo.IntentionCode + ",";
                    
                    baseinfo.BelongCityName = city;
                    baseinfo.BelongCityId = new Guid(cityid);
                    baseinfo.BelongCompany = company;
                    baseinfo.BelongCompanyId = new Guid(companyid);
                    baseinfo.BelongDepart = dep;
                    baseinfo.BelongDepartId = new Guid(depid);
                    baseinfo.BelongEmp = emp;
                    baseinfo.BelongEmpId = new Guid(empid);
                    baseinfo.UpdateEmp = CurrentUserInfo.UserName;
                    baseinfo.UpdateEmpId = CurrentUserInfo.UserId;
                    baseinfo.UpdateTime = DateTime.Now;
                    Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(baseinfo);
                    
                    
                }
            }

            string text = CurrentUserInfo.UserName + "：意向书下发。意向书编号：" + codelist;
            AddLog(text, BusinessType.BusinessTypeComboList()["OprType_DeliverIntention"].ToString());
            
            if (failid.Length > 0)
                return "{success:'1',msg:'下发成功,其中部分发放失败。失败意向书编号：" + failid.Substring(0,failid.Length-1) + "',data:''}";
            else
                return "{success:'1',msg:'下发成功',data:''}";
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    

    /// <summary>
    /// 获取实体
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetModel(HttpContext context)
    {
        try
        {
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo model = null;

            model = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(new Guid(context.Request["modelid"]));

            if (model != null)
            {
                return retExecResult(Constants.ExecResult.Succ, "数据不存在，获取信息成功！", model);
            }
            else
            {
                return retExecResult(Constants.ExecResult.Error, "数据不存在，获取信息失败！", "");
            }
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }

    //*******************************************
    //功能概要       ：获得意向书一览
    //参数説明       ：context 请求的上下文
    //返回值説明     ：无
    //功能詳細       ：获得意向书一览
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-27
    //*******************************************
    private string Search(HttpContext context)
    {
        //返回数据
        string strRet = string.Empty;

        StringBuilder sb = new StringBuilder();
        sb.Append(" (1=1) ");        
        ////权限
        //if (CurrentUserInfo.ContainsPermit(Constants.Permit_Intent_Search_All))
        //{
        //    sb.Append(" (1=1) ");
        //}
        //else if (CurrentUserInfo.ContainsPermit(Constants.Permit_Intent_Search_City))
        //{
        //    sb.AppendFormat(" (BelongCityId='{0}') ", CurrentUserInfo.CityId.ToString());
        //}
        //else if (CurrentUserInfo.ContainsPermit(Constants.Permit_Intent_Search_Company))
        //{
        //    sb.AppendFormat(" (BelongCompanyId='{0}') ", CurrentUserInfo.CompanyId.ToString());
        //}
        //else if (CurrentUserInfo.ContainsPermit(Constants.Permit_Intent_Search_Depart))
        //{
        //    sb.Append(" EXISTS(");
        //    sb.Append(string.Format("Select 1 from t_Business_EmpSetting M WHERE t_Intention_BaseInfo.BelongDepartId=M.DepartId And M.Userid= '{0}' and SearchIntention=1", CurrentUserInfo.UserId.ToString()));
        //    sb.Append(") ");
        //}
        //else
        //    sb.AppendFormat(" (LastEmployeeId='{0}') ", CurrentUserInfo.UserId.ToString());
        
        
        //排序
        string strOrderField = "IntentionCode desc";
        if (!string.IsNullOrEmpty(context.Request["sort"]))
        {
            strOrderField = context.Request["sort"];
        }
        if (!string.IsNullOrEmpty(context.Request["Status"]))
        {
            sb.AppendFormat(" and Status = '{0}'", context.Request["Status"]);
        }
        if (!string.IsNullOrEmpty(context.Request["BusinessType"]))
        {
            sb.AppendFormat(" and BusinessType = '{0}'", context.Request["BusinessType"]);
        }
        if (!string.IsNullOrEmpty(context.Request["DateFr"]) && context.Request["DateFr"] != "请选择下发时间")
        {
            sb.AppendFormat(" and DeliverTime >= '{0}'", context.Request["DateFr"]);
        }
        if (!string.IsNullOrEmpty(context.Request["DateTo"]) && context.Request["DateTo"] != "请选择下发时间")
        {
            sb.AppendFormat(" and DeliverTime <= '{0}'", context.Request["DateTo"]);
        }
        if (!string.IsNullOrEmpty(context.Request["IntentionCode"]) && context.Request["IntentionCode"] != "请输入意向书编号...")
        {
            sb.AppendFormat(" and IntentionCode like '%{0}%'", context.Request["IntentionCode"]);
        }
        
        Guid city = (string.IsNullOrEmpty(context.Request["cityid"])) ? Guid.Empty : new Guid(context.Request["cityid"]);
        Guid company = (string.IsNullOrEmpty(context.Request["companyid"])) ? Guid.Empty : new Guid(context.Request["companyid"]);
        Guid businessdistrict = (string.IsNullOrEmpty(context.Request["areaid"])) ? Guid.Empty : new Guid(context.Request["areaid"]);
        Guid departs = (string.IsNullOrEmpty(context.Request["departid"])) ? Guid.Empty : new Guid(context.Request["departid"]);
        Guid employee = (string.IsNullOrEmpty(context.Request["userid"])) ? Guid.Empty : new Guid(context.Request["userid"]);

        if (employee != Guid.Empty)
        {
            sb.AppendFormat(" and LastEmployeeId = '{0}'", employee);
        }
        else if (departs != Guid.Empty)
        {
            sb.AppendFormat(" and BelongDepartId = '{0}'", departs);
        }
        else if (businessdistrict != Guid.Empty)
        {
            Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo item = null;
            string strCachkey = string.Format(Chenxin.Lib.Cache.CacheDataType.GLOBAL_DEPARTMENT, businessdistrict);
            Chenxin.Lib.Cache.CacheService cs = new Chenxin.Lib.Cache.CacheService(Chenxin.Lib.Cache.CacheConn.xCacheConn.GLOBAL);
            item = cs.GetObject<Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo>(strCachkey);
            if (!cs.Hit)
            {
                item = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(businessdistrict);
                if (item != null) cs.Set(strCachkey, item, DateTime.Now.AddDays(1));
            }

            if (item == null)
            {
                return retExecResult(Constants.ExecResult.Error, "获取商圈或分类数据丢失", "");
            }
            sb.AppendFormat(" and (BelongDepartId in (Select DepartId from v_Hr_DepartmentInfo where DepartSrc like '{0}%'))", item.DepartSrc);
        }
        else if (company != Guid.Empty)
        {
            sb.AppendFormat(" and BelongCompanyId = '{0}'", company);
        }
        else if (city != Guid.Empty)
        {
            sb.AppendFormat(" and BelongCityId = '{0}'", city);
        }
        else
        {
            sb.AppendFormat(" and BelongCompanyId = '{0}'", CurrentUserInfo.CompanyId);
        }
        
        try
        {
            //条件
            string strWhere = sb.ToString();
            //页码
            int strPageIndex = (string.IsNullOrEmpty(context.Request["pageindex"])) ? 1 : int.Parse(context.Request["pageindex"]) + 1;//页码
            //页显示行数
            int strPageSize = (string.IsNullOrEmpty(context.Request["pagesize"])) ? 30 : int.Parse(context.Request["pagesize"]);//页记录数
            //欲选择字段列表 
            string FieldList = "*,business";
            //子查询欲选择字段列表
            string TableFieldList = "*,dbo.FN_GetBussinessByDepartID(BelongDepartId) as business";
            //所要查询的表名
            string TableName = "t_Intention_BaseInfo ";
            //根据sql执行查询
            DataSet ds = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetList(strPageIndex, strPageSize, strOrderField, TableName, strWhere, FieldList, TableFieldList, true);
            
            Constants.Pagination cp = GetJson(ds);
            strRet = string.Format("{{success:1,msg:'',data:{{count:{0},html:'{1}'}}}}", cp.count, cp.data);
            return strRet;
        }
        catch (Exception ex)
        {
            strRet = retExecResult(Constants.ExecResult.Error, ex.Message, "");
            return strRet;
        }
    }

    //*******************************************
    //功能概要       ：意向书编号发放
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：意向书编号发放
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-30
    //*******************************************
    private string Issue(HttpContext context)
    {
        try
        {
            //意向书信息
            string CreateInfo = context.Request.Params["model"];

            //意向书主表
            t_Intention_BaseInfo bllIntention = new t_Intention_BaseInfo();

            //意向发放
            t_Intention_CreateInfo bllCreate = new t_Intention_CreateInfo();

            //意向日志
            t_Intention_DeliverLogs bllLogs = new t_Intention_DeliverLogs();

            string[] strIntention = CreateInfo.Split(',');
            string strCityId = strIntention[4].ToString();
            strCityId = "BelongCityId" + strCityId.Substring(6);
            string strCity = strIntention[5].ToString();
            strCity = "BelongCityName" + strCity.Substring(4);
            string strCompanyId = strIntention[6].ToString();
            strCompanyId = "BelongCompanyId" + strCompanyId.Substring(9);
            string strCompany = strIntention[7].ToString();
            strCompany = "BelongCompany" + strCompany.Substring(7);
            string strDepartId = strIntention[8].ToString();
            strDepartId = "BelongDepartId" + strDepartId.Substring(8);
            string strDepart = strIntention[9].ToString();
            strDepart = "BelongDepart" + strDepart.Substring(6);
            string strEmployeeId = strIntention[10].ToString();
            strEmployeeId = "BelongEmpId" + strEmployeeId.Substring(6);
            string strEmployee = strIntention[11].ToString();
            strEmployee = "BelongEmp" + strEmployee.Substring(4);
            string strIntentionCode = strIntention[0].ToString();
            string strMaxCode = "{StartCode" + strIntentionCode.Substring(14);
            string strCodeCount = strIntention[1].ToString();
            string strReceiveCityId = "ReceiveCityId" + strIntention[4].ToString().Substring(6);
            string strReceiveCity = "ReceiveCity" + strIntention[5].ToString().Substring(4);
            string strReceiveCompanyId = "ReceiveCompanyId" + strIntention[6].ToString().Substring(9);
            string strReceiveCompany = "ReceiveCompany" + strIntention[7].ToString().Substring(7);
            string strReceiveDepartId = "ReceiveDepartId" + strIntention[8].ToString().Substring(8);
            string strReceiveDepart = "ReceiveDepart" + strIntention[9].ToString().Substring(6);
            string strReceiveEmpId = "ReceiveEmpId" + strIntention[10].ToString().Substring(6);
            string strReceiveEmp = "ReceiveEmp" + strIntention[11].ToString().Substring(4);
            string[] tempUser = strEmployee.Split('(');
            strEmployee = tempUser[0] + "\"}";
            string intent = strIntentionCode + "," + strIntention[2].ToString() + "," + strIntention[3].ToString() + "," + strCityId + "," + strCity + "," + strCompanyId + "," + strCompany + "," + strDepartId + "," + strDepart + "," + strEmployeeId + "," + strEmployee;
            string create = strMaxCode + "," + strCodeCount + "," + strIntention[2].ToString() + "," + strIntention[3].ToString() + "," + strCityId + "," + strCity + "," + strCompanyId + "," + strCompany + "," + strDepartId + "," + strDepart + "," + strEmployeeId + "," + strEmployee;
            string log = strIntentionCode + "," + strReceiveCityId + "," + strReceiveCity + "," + strReceiveCompanyId + "," + strReceiveCompany + "," + strReceiveDepartId + "," + strReceiveDepart + "," + strReceiveEmpId + "," + strReceiveEmp;
            
            //意向书信息格式化
            Chenxin.Lib.Business.Entity.t_Intention_CreateInfo entCreateInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_CreateInfo)JsonHelp.Convert2Entity(create,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_CreateInfo));

            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention =
                (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(intent,
                        typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

            Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs entDeliverLogs =
                (Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs)JsonHelp.Convert2Entity(log,
                        typeof(Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs));
            
            string strYear = (DateTime.Today.Year).ToString();
            if (!string.IsNullOrEmpty(context.Request.Params["code_year"]))
                strYear = context.Request.Params["code_year"];
            strYear = strYear.Substring(2, 2);

            if (entCreateInfo.CodeCount > 10)
            {
                return retExecResult(Constants.ExecResult.Error, "每次发放的数量最多为10！", "");
            }

            bool blUpdate = UpdCode(entIntention, entCreateInfo.CodeCount.ToString(), strYear);
            if (blUpdate == false)
            {
                return retExecResult(Constants.ExecResult.Error, "请重新获取起始编号，此编号已使用！", "");
            }            
            
            entIntention = CompleteIntention(entIntention, "发放");
            entDeliverLogs = CompleteDeliverLogs(entDeliverLogs);
            entDeliverLogs.ReceiveEmp = entDeliverLogs.ReceiveEmp.Remove(entDeliverLogs.ReceiveEmp.IndexOf("("));
            string idlist = "";
            for (int i = 0; i < entCreateInfo.CodeCount; i++)
            {
                entIntention.IntentionId = Guid.NewGuid();
                entDeliverLogs.RecordId = Guid.NewGuid();
                entIntention.IntentionCode = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetIntentionCode(entIntention.BelongCompanyId, entIntention.BusinessType.ToString(), entIntention.IntentionType.ToString(), strYear);
                idlist += entIntention.IntentionCode + ",";
                entDeliverLogs.IntentionId = entIntention.IntentionId;
                entDeliverLogs.IntentionCode = entIntention.IntentionCode;
                entDeliverLogs.Status = 10;
                bllIntention.Add(entIntention);
                bllLogs.Add(entDeliverLogs);
            }

            entCreateInfo.RecordId = Guid.NewGuid();
            entCreateInfo.IntentionType = entIntention.IntentionType;
            entCreateInfo.CreateDate = DateTime.Now;
            entCreateInfo.CreateEmpId = CurrentUserInfo.UserId;
            entCreateInfo.CreateEmp = CurrentUserInfo.UserName;
            bllCreate.Add(entCreateInfo);

            string text = CurrentUserInfo.UserName + "：意向书发放。意向书编号：" + idlist;
            AddLog(text, BusinessType.BusinessTypeComboList()["OprType_IssueIntention"].ToString());
            
            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_Issue, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, "请输入相应信息！", "请输入相应信息！");
        }
    }

    /// <summary>
    /// 意向编号编辑(现已不用)
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string CodeFomm(int IntentionCode, Guid BelongCompanyId, string BusinessType, string IntentionType)
    {
        //取得前缀
        string strComCode = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetComCode(BelongCompanyId);
        string strYear = ((DateTime.Today.Year).ToString()).Substring(2, 2);
        string rtCode = string.Empty;
        string rtBt = string.Empty;
        string rtIt = string.Empty;
        string reIc = IntentionCode.ToString();
        switch(BusinessType)
        {
            case "10":
                rtBt = "MY";
                break;
            case "20":
                rtBt = "ZY";
                break;
        }
        
        switch(IntentionType)
        {
            case "10":
                rtIt = "MMXY";
                    break;
            case "20":
                    rtIt = "JJXY";
                    break;
        }
        
        for(int i=reIc.Length; i<6; i++)
        {
            reIc = "0" + reIc;
        }
        rtCode = strComCode + "-" + rtBt + "-" + rtIt + "-" + strYear + "-" + reIc;
        return rtCode;
    }

    /// <summary>
    /// 获取意向编号
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private string GetCode(HttpContext context)
    {
        try
        {
            string BusinessType = context.Request.Params["BusinessType"];
            string IntentionType = context.Request.Params["IntentionType"];
            string cityid = context.Request.Params["cityid"];
            string companyid = context.Request.Params["companyid"];
            
            //取得公司前缀
            string strComCode = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetComCode(new Guid(companyid));
            if (string.IsNullOrEmpty(strComCode))
            {
                return retExecResult(Constants.ExecResult.Succ, "请选择公司！", "");
            }

            string strYear = ((DateTime.Today.Year).ToString()).Substring(2, 2);
            if (!string.IsNullOrEmpty(context.Request.Params["code_year"]))
                strYear = context.Request.Params["code_year"].ToString().Substring(2, 2);
            StringBuilder sb = new StringBuilder();
            sb.Append("where 1=1");
            sb.AppendFormat(" and PrefixCode = '{0}' and BusinessType = '{1}' and IntentionType = '{2}' and IntentionYear = '{3}' ", strComCode, BusinessType, IntentionType, strYear);
            string strWhere = sb.ToString();
            Chenxin.Lib.Business.BLL.AutoCode_IntentionControllerInfo bllIntentionControllerInfo = new AutoCode_IntentionControllerInfo();
            string maxCode = bllIntentionControllerInfo.GetCode(strWhere);

            if (string.IsNullOrEmpty(maxCode))
                maxCode = "1";
           
            return "{success:1,msg:'获取信息成功！',data:{IntentionCode:'" + maxCode + "'}}";
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message, "");
        }
    }
    
    /// <summary>
    /// 验证意向编号
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    private bool UpdCode(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention, string strCodeCount, string strYear)
    {
        try
        {
            Chenxin.Lib.Business.Entity.AutoCode_IntentionControllerInfo model = new Chenxin.Lib.Business.Entity.AutoCode_IntentionControllerInfo();

            //取得公司前缀
            string strComCode = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetComCode(entIntention.BelongCompanyId);
            if (string.IsNullOrEmpty(strComCode))
            {
                return false;
            }

            StringBuilder sb = new StringBuilder();
            sb.Append("where 1=1");
            sb.AppendFormat(" and PrefixCode = '{0}' and BusinessType = '{1}' and IntentionType = '{2}' and IntentionYear = '{3}' ", strComCode, entIntention.BusinessType, entIntention.IntentionType, strYear);
            string strWhere = sb.ToString();
            Chenxin.Lib.Business.BLL.AutoCode_IntentionControllerInfo bllIntentionControllerInfo = new AutoCode_IntentionControllerInfo();
            Chenxin.Lib.Business.Entity.AutoCode_IntentionControllerInfo entCode = new Chenxin.Lib.Business.Entity.AutoCode_IntentionControllerInfo(); ;
            entCode = bllIntentionControllerInfo.GetCurrCode(strWhere);

            if (entCode != null && (int.Parse(entIntention.IntentionCode) <= int.Parse(entCode.MaxCode.ToString())))
            {
                return false;                
            }
            return true;            
        }
        catch (Exception ex)
        {
            return false;
        }
    }
    
    //*******************************************
    //功能概要       ：意向书编号领用
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：意向书编号领用
    //作成者         ：zou.xiaochun
    //作成日         ：2010-08-31
    //*******************************************
    private string GetLetter(HttpContext context)
    {
        //意向书信息
        string IntentionInfo = context.Request.Params["model"];

        //意向书主表
        t_Intention_BaseInfo bllIntention = new t_Intention_BaseInfo();

        //意向日志
        t_Intention_DeliverLogs bllLogs = new t_Intention_DeliverLogs();

        //意向书信息格式化
        Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(IntentionInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

        Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs entDeliverLogs = new Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs();
        entDeliverLogs.RecordId = Guid.NewGuid();
       
        entIntention = CompleteIntention(entIntention,"领用");
        entDeliverLogs.ReceiveCityId = entIntention.BelongCityId;
        entDeliverLogs.ReceiveCity = entIntention.BelongCityName;
        entDeliverLogs.ReceiveCompanyId = entIntention.BelongCompanyId;
        entDeliverLogs.ReceiveCompany = entIntention.BelongCompany;
        entDeliverLogs.ReceiveDepartId = entIntention.BelongDepartId;
        entDeliverLogs.ReceiveDepart = entIntention.BelongDepart;
        entDeliverLogs.ReceiveEmpId = entIntention.LastEmployeeId;
        entDeliverLogs.ReceiveEmp = entIntention.LastEmployee;
        entDeliverLogs = CompleteDeliverLogs(entDeliverLogs);
        entDeliverLogs.Status = 20;
        entDeliverLogs.IntentionId = entIntention.IntentionId;
        entDeliverLogs.IntentionCode = entIntention.IntentionCode;
        bllIntention.Update(entIntention);
        bllLogs.Add(entDeliverLogs);

        string text = CurrentUserInfo.UserName + "：意向书领用。意向书编号：" + entIntention.IntentionCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_LetterIntention"].ToString());
        
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_GetLetter, "");
    }

    //*******************************************
    //功能概要       ：意向书资料输入
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理信息提示
    //功能詳細       ：意向书资料输入
    //作成者         ：zou.xiaochun
    //作成日         ：2010-09-01
    //*******************************************
    private string InputInfo(HttpContext context)
    {
        //意向书信息
        string IntentionInfo = context.Request.Params["model"];

        //意向书主表
        t_Intention_BaseInfo bllIntention = new t_Intention_BaseInfo();

        //意向书信息格式化
        Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(IntentionInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

        entIntention = CompleteIntention(entIntention, "录入");
        
        //获取相应房源信息
        Chenxin.Lib.House.Entity.House_BaseInfo entHouseInfo = Chenxin.Lib.House.BLL.House_BaseInfo.GetHouseInfoEntity(entIntention.HouseId.ToString());
        if (entHouseInfo != null)
        {
            entIntention.HouseCode = entHouseInfo.HouseCode;
        }
        entIntention.TotalMoney = entIntention.FirstMoney;
        bllIntention.Update(entIntention);

        string text = CurrentUserInfo.UserName + "：意向书资料输入。意向书编号：" + entIntention.IntentionCode;
        AddLog(text, BusinessType.BusinessTypeComboList()["OprType_InputIntention"].ToString());
        
        return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_InputInfo, "");
    }

    //*******************************************
    //功能概要       ：失效意向
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：失效意向
    //作成者         ：tianno
    //作成日         ：2010-09-01
    //*******************************************
    private string UnEffectiveInfo(HttpContext context)
    {
        try
        {
            //意向书信息
            string CreateInfo = context.Request.Params["model"];
            //model转实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(CreateInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

            //根据ID 得到原意向数据
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo oldInfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entInfo.IntentionId);

            //填充数据
            oldInfo.HouseAddress = entInfo.HouseAddress;
            oldInfo.TotalPrice = entInfo.TotalPrice;
            oldInfo.CustomerName_Sale = entInfo.CustomerName_Sale;
            oldInfo.CustomerName_Buy = entInfo.CustomerName_Buy;
            oldInfo.FirstMoney = entInfo.FirstMoney;
            oldInfo.Status = -40;
            oldInfo.StatusDescription = entInfo.StatusDescription;
            oldInfo.UpdateEmp = CurrentUserInfo.UserName;
            oldInfo.UpdateEmpId = CurrentUserInfo.UserId;
            oldInfo.UpdateTime = DateTime.Now;

            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(oldInfo);

            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_UnEffectiveInfo, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message.ToString(), "");
        }
    }

    //*******************************************
    //功能概要       ：作废意向
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：作废意向
    //作成者         ：tianno
    //作成日         ：2010-09-01
    //*******************************************
    private string CancelInfo(HttpContext context)
    {
        try
        {
            //意向书信息
            string CreateInfo = context.Request.Params["model"];
            //model转实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(CreateInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

            //根据ID 得到原意向数据
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo oldInfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entInfo.IntentionId);

            //填充数据
            oldInfo.HouseAddress = entInfo.HouseAddress;
            oldInfo.TotalPrice = entInfo.TotalPrice;
            oldInfo.CustomerName_Sale = entInfo.CustomerName_Sale;
            oldInfo.CustomerName_Buy = entInfo.CustomerName_Buy;
            oldInfo.Status = -20;
            oldInfo.StatusDescription = entInfo.StatusDescription;
            oldInfo.UpdateEmp = CurrentUserInfo.UserName;
            oldInfo.UpdateEmpId = CurrentUserInfo.UserId;
            oldInfo.UpdateTime = DateTime.Now;

            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(oldInfo);

            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_CancelInfo, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message.ToString(), "");
        }
    }

    //*******************************************
    //功能概要       ：遗失意向
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：遗失意向
    //作成者         ：tianno
    //作成日         ：2010-09-01
    //*******************************************
    private string LoseInfo(HttpContext context)
    {
        try
        {
            //意向书信息
            string CreateInfo = context.Request.Params["model"];
            //model转实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(CreateInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

            //根据ID 得到原意向数据
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo oldInfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entInfo.IntentionId);

            //填充数据
            oldInfo.HouseAddress = entInfo.HouseAddress;
            oldInfo.TotalPrice = entInfo.TotalPrice;
            oldInfo.Status = -30;
            oldInfo.LostItems = entInfo.LostItems;
            oldInfo.GetAuthorizeDate = entInfo.GetAuthorizeDate;
            oldInfo.StatusDescription = entInfo.StatusDescription;
            oldInfo.UpdateEmp = CurrentUserInfo.UserName;
            oldInfo.UpdateEmpId = CurrentUserInfo.UserId;
            oldInfo.UpdateTime = DateTime.Now;

            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(oldInfo);

            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_LoseInfo, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message.ToString(), "");
        }
    }

    //*******************************************
    //功能概要       ：法务回收
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：法务回收（把所属业务员及部门置空）
    //作成者         ：tianno
    //作成日         ：2010-09-01
    //*******************************************
    private string RecallByFW(HttpContext context)
    {
        try
        {
            string IntentionId = context.Request.Params["modelid"];
            
            //获取意向书实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo intentinfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(new Guid(IntentionId));
            
            //填写日志
            Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs logs = new Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs();
            logs.RecordId = Guid.NewGuid();
            logs.IntentionId = intentinfo.IntentionId;
            logs.IntentionCode = intentinfo.IntentionCode;
            logs.DeliverTime = DateTime.Now;
            logs.DeliverCity = logs.ReceiveCity = intentinfo.BelongCityName;
            logs.DeliverCityId = logs.ReceiveCityId = intentinfo.BelongCityId;
            logs.DeliverCompany = logs.ReceiveCompany = intentinfo.BelongCompany;
            logs.DeliverCompanyId = logs.ReceiveCompanyId = intentinfo.BelongCompanyId;
            logs.DeliverDepart = intentinfo.BelongDepart;
            logs.DeliverDepartId = intentinfo.BelongDepartId;
            logs.DeliverEmp = intentinfo.LastEmployee;
            logs.DeliverEmpId = intentinfo.LastEmployeeId;
            logs.ReceiveEmp = intentinfo.CreateEmp;
            logs.ReceiveEmpId = intentinfo.CreateEmpId;
            logs.Status = 30;
            
            //意向书回收
            intentinfo.BelongEmp = "";
            intentinfo.BelongEmpId = Guid.Empty;
            intentinfo.DeliverTime = null;
            intentinfo.BelongDepart = "";
            intentinfo.BelongDepartId = Guid.Empty;
            intentinfo.LastEmployee = "";
            intentinfo.LastEmployeeId = Guid.Empty;
            intentinfo.LastEmployeeGetTime = null;
            intentinfo.Status = -200;

            //更新
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(intentinfo);
            Chenxin.Lib.Business.DAL.t_Intention_DeliverLogs.Add(logs);

            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_RecallByFW, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message.ToString(), "");
        }
    }

    //*******************************************
    //功能概要       ：门店回收
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：门店回收(把所属业务员置空)
    //作成者         ：tianno
    //作成日         ：2010-09-01
    //*******************************************
    private string RecallByMD(HttpContext context)
    {
        try
        {
            string IntentionId = context.Request.Params["modelid"];

            //获取意向书实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo intentinfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(new Guid(IntentionId));

            //填写日志
            Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs logs = new Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs();
            logs.RecordId = Guid.NewGuid();
            logs.IntentionId = intentinfo.IntentionId;
            logs.IntentionCode = intentinfo.IntentionCode;
            logs.DeliverTime = DateTime.Now;
            logs.DeliverCity = logs.ReceiveCity = intentinfo.BelongCityName;
            logs.DeliverCityId = logs.ReceiveCityId = intentinfo.BelongCityId;
            logs.DeliverCompany = logs.ReceiveCompany = intentinfo.BelongCompany;
            logs.DeliverCompanyId = logs.ReceiveCompanyId = intentinfo.BelongCompanyId;
            logs.DeliverDepart = logs.ReceiveDepart = intentinfo.BelongDepart;
            logs.DeliverDepartId = logs.ReceiveDepartId = intentinfo.BelongDepartId;
            logs.DeliverEmp = intentinfo.LastEmployee;
            logs.DeliverEmpId = intentinfo.LastEmployeeId;
            logs.ReceiveEmp = intentinfo.BelongEmp;
            logs.ReceiveEmpId = intentinfo.BelongEmpId;
            logs.Status = 30;
            Chenxin.Lib.Business.DAL.t_Intention_DeliverLogs.Add(logs);

            //意向书回收
            intentinfo.LastEmployee = "";
            intentinfo.LastEmployeeId = Guid.Empty;
            intentinfo.LastEmployeeGetTime = null;
            intentinfo.Status = -200;

            //更新
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(intentinfo);

            return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_RecallByMD, "");
        }
        catch (Exception ex)
        {
            return retExecResult(Constants.ExecResult.Error, ex.Message.ToString(), "");
        }
    }


    //*******************************************
    //功能概要       ：添加意向金
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：添加意向金
    //作成者         ：tianno
    //作成日         ：2010-09-02
    //*******************************************
    private string AddMoney(HttpContext context)
    {
        try
        {
            //添加意向金信息
            string CreateInfo = context.Request.Params["model"];

            
            
            //model转实体
            Chenxin.Lib.Business.Entity.t_Intention_AddMoneyInfo entInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_AddMoneyInfo)JsonHelp.Convert2Entity(CreateInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_AddMoneyInfo));
            
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo baseinfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entInfo.IntentionId);

            entInfo.RecordId = Guid.NewGuid();
            entInfo.Status = 1;
            entInfo.IntentionCode = baseinfo.IntentionCode;
            entInfo.AddEmployee = CurrentUserInfo.UserName;
            entInfo.AddEmployeeId = CurrentUserInfo.UserId;
            entInfo.AddTime = DateTime.Now;

            Chenxin.Lib.Business.DAL.t_Intention_AddMoneyInfo.Add(entInfo);
            
            //更新意向基本信息
            
            baseinfo.TotalMoney = baseinfo.TotalMoney + entInfo.AddedMoney;
            baseinfo.UpdateEmp = CurrentUserInfo.UserName;
            baseinfo.UpdateEmpId = CurrentUserInfo.UserId;
            baseinfo.UpdateTime = DateTime.Now;
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(baseinfo);
            
            return string.Format("{{success:'1',msg:'添加成功',data:''}}");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}',data:''}}", ex.Message);
        }
    }


    //*******************************************
    //功能概要       ：变更业务员
    //参数説明       ：context 请求上下文
    //返回值説明     ：程序处理结果
    //功能詳細       ：将意向书变更给其他业务员
    //作成者         ：tianno
    //作成日         ：2010-09-02
    //*******************************************
    private string ChangeUser(HttpContext context)
    {
        try
        {
            //意向书信息
            string CreateInfo = context.Request.Params["model"];
            //model转实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entInfo =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(CreateInfo,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));
            
            //得到原意向书实体
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo oldInfo = Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.GetModel(entInfo.IntentionId);
            
            //添加日志实体
            Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs logs = new Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs();
            logs.RecordId = Guid.NewGuid();
            logs.IntentionId = oldInfo.IntentionId;
            logs.IntentionCode = oldInfo.IntentionCode;
            logs.DeliverTime = DateTime.Now;
            logs.DeliverEmpId = oldInfo.LastEmployeeId;
            logs.DeliverEmp = oldInfo.LastEmployee;
            logs.DeliverDepartId = oldInfo.BelongDepartId;
            logs.DeliverDepart = oldInfo.BelongDepart;
            logs.DeliverCompanyId = logs.ReceiveCompanyId = oldInfo.BelongCompanyId;
            logs.DeliverCompany = logs.ReceiveCompany = oldInfo.BelongCompany;
            logs.DeliverCityId = logs.ReceiveCityId = oldInfo.BelongCityId;
            logs.ReceiveCity = logs.DeliverCity = oldInfo.BelongCityName;
            logs.ReceiveDepartId = entInfo.BelongDepartId;
            logs.ReceiveDepart = entInfo.BelongDepart;
            logs.ReceiveEmp = entInfo.LastEmployee;
            logs.ReceiveEmpId = entInfo.LastEmployeeId;
            logs.Status = 40;
            Chenxin.Lib.Business.DAL.t_Intention_DeliverLogs.Add(logs);

            //变更处理
            oldInfo.LastEmployee = entInfo.LastEmployee;
            oldInfo.LastEmployeeId = entInfo.LastEmployeeId;
            oldInfo.LastEmployeeGetTime = entInfo.LastEmployeeGetTime;
            oldInfo.BelongDepart = entInfo.BelongDepart;
            oldInfo.BelongDepartId = entInfo.BelongDepartId;
            oldInfo.BelongEmp = entInfo.BelongEmp;
            oldInfo.BelongEmpId = entInfo.BelongEmpId;
            oldInfo.UpdateEmp = CurrentUserInfo.UserName;
            oldInfo.UpdateEmpId = CurrentUserInfo.UserId;
            oldInfo.UpdateTime = DateTime.Now;
            Chenxin.Lib.Business.DAL.t_Intention_BaseInfo.Update(oldInfo);
            
            return string.Format("{{success:'1',msg:'变更成功',data:''}}");
        }
        catch (Exception ex)
        {
            return string.Format("{{success:'0',msg:'{0}',data:''}}", ex.Message);
        }
    }

    /// <summary>
    /// 意向开单
    /// </summary>
    /// <param name="context"></param>
    private string BillAdd(HttpContext context)
    {
        //开单信息
        string billgeted = context.Request.Params["model"];
        //明细信息
        string lsBillItem = context.Request.Params["lsBillItem"];

        //开单业务类
        Chenxin.Lib.Business.BLL.t_Intention_BillGetedInfo bllBillGeted = new Chenxin.Lib.Business.BLL.t_Intention_BillGetedInfo();
        
        //明细信息
        t_Intention_BillItemsInfo bllBillItem = new t_Intention_BillItemsInfo();

        t_Intention_BaseInfo bllIntent = new t_Intention_BaseInfo();

        //明细信息
        List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo> lsModelOfBill = new List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo>();

        //明细信息列表
        if (!string.IsNullOrEmpty(lsBillItem))
        {
            lsModelOfBill = (List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo>)JsonHelp.Convert2Entity(lsBillItem,
                                typeof(List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo>));
        }

        //开单信息
        Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo entBillGeted =
            (Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo)JsonHelp.Convert2Entity(billgeted,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo));

        string[] strIntent = billgeted.Split(',');
        string intent = "{" + strIntent[2] + "," + strIntent[4] + "}";

        Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntent =
            (Chenxin.Lib.Business.Entity.t_Intention_BaseInfo)JsonHelp.Convert2Entity(intent,
                    typeof(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo));

        entBillGeted = CompleteBillGeted(entBillGeted,1);

        entIntent = CompleteIntention(entIntent, "开单");

        //①开单信息录入
        bllBillGeted.Add(entBillGeted);
        bllIntent.Update(entIntent);

        //②明细信息录入
        for (int idx = 0; idx < lsModelOfBill.Count; idx++)
        {
            (lsModelOfBill[idx]).BillId = entBillGeted.BillId;
            (lsModelOfBill[idx]).RecordId = Guid.NewGuid();
            (lsModelOfBill[idx]).AddTime = DateTime.Now;
            bllBillItem.Add(lsModelOfBill[idx]);
        }
        
        //****************获取打印信息****************************
        Chenxin.Lib.Business.Entity.v_PrintMoneyInfo model = Chenxin.Lib.Business.DAL.v_PrintMoneyInfo.GetModel(entBillGeted.BillId);
        if (model == null) return retExecResult(Constants.ExecResult.Error, "获取开单信息失败，请联系管理员！", "");

        model.PrintTime = DateTime.Now.ToShortDateString();
        string str = "";
        Chenxin.Lib.Utility.InitialHelper.TranslateNumberToChinese(model.GetedMoney.ToString(), out str);
        model.GetedMoneyBig = str;

        string strSql = "IntentionId='" + entBillGeted.BillId + "'";

        List<Chenxin.Lib.Business.Entity.t_Intention_BillPrintInfo> list = Chenxin.Lib.Business.DAL.t_Intention_BillPrintInfo.GetListArray(strSql);
        model.PrintCount = list.Count + 1;

        //获得意向金款项List        
        StringBuilder sb = new StringBuilder();

        if (model.InOrOut == 1)
        {
            List<Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo> itemslist = Chenxin.Lib.Business.DAL.t_Intention_BillItemsInfo.GetListArray(" BillId='" + model.BillId + "'");
            sb.Append("<table width=\"100%\" cellspacing=\"1\" style=\"margin-left:15px;\" class=\"tabsorternew table_archive\">");
            sb.Append("<tr>");
            sb.AppendFormat("<th style=\"text-align:center;width:15%;font-size:13px;\">支付方式</th><th style=\"text-align:center;width:15%;font-size:13px;\">支付金额</th><th style=\"text-align:center;width:15%;font-size:13px;\">付款方名称</th><th style=\"text-align:center;font-size:13px;width:15%;\">付款方账户</th>");
            sb.Append("</tr>");

            if (itemslist.Count < 1)
            {
                sb.Append("<tr><td colspan=\"4\" style=\"text-align:center;height: 25px;font-size:13px;\">无款项明细记录</td></tr>");
            }
            else
            {
                foreach (Chenxin.Lib.Business.Entity.t_Intention_BillItemsInfo item in itemslist)
                {
                    sb.Append("<tr>");
                    sb.AppendFormat("<td style=\"text-align:center;font-size:13px;height: 25px;\">{0}</td><td style=\"text-align:center;font-size:13px;\">{1}</td><td style=\"text-align:center;font-size:13px;\">{2}</td><td style=\"text-align:center;font-size:13px;\">{3}</td>", item.PayMode, item.PayMoney, item.PayName, item.PayCode);
                    sb.Append("</tr>");
                }
            }
            sb.Append("</table>");
        }
        model.Details = sb.ToString();

        return string.Format("{{success:1,msg:'意向金开单成功！',data:{{model:{0}}}}}", JsonHelp.Convert2Json(model));
        //**********************************************************
        
       // return retExecResult(Constants.ExecResult.Succ, Resources.Message.Msg_Intention_BillGeted, "");
    }

    //*******************************************
    //功能概要       ：转化为翻页结构体格式
    //参数説明       ：dtData 要转化的原始数据
    //               ：intShowRows 一页所要显示的条数
    //               ：intCurPage 当前的页码
    //               ：intTotal 数据总条数
    //返回值説明     ：翻页结构体
    //功能詳細       ：转化为翻页结构体格式
    //作成者         ：zou.xiaochu
    //作成日         ：2010-08-30 
    //*******************************************
    public Constants.Pagination GetJson(System.Data.DataSet dsData)
    {
        Constants.Pagination stuPag = new Constants.Pagination();
        System.Data.DataRow row;
        DateTime dtTempTime;

        System.Text.StringBuilder strData = new System.Text.StringBuilder();

        for (int idxRow = 0; idxRow < dsData.Tables[0].Rows.Count; idxRow++)
        {
            row = dsData.Tables[0].Rows[idxRow];

            strData.AppendFormat("<dl id=\"{0}\">", row["IntentionId"].ToString());
            strData.AppendFormat("<dd style=\"display: none;\">{0}</dd>", row["IntentionId"].ToString());
            if (!string.IsNullOrEmpty(row["Status"].ToString()))
            {
                switch (int.Parse(row["Status"].ToString()))
                {
                    case -200:
                        strData.AppendFormat("<dd>{0}</dd>", "未领用");
                        break;
                    case -100:
                        strData.AppendFormat("<dd>{0}</dd>", "未使用");
                        break;
                    case -30:
                        strData.AppendFormat("<dd>{0}</dd>", "遗失");
                        break;
                    case -20:
                        strData.AppendFormat("<dd>{0}</dd>", "作废");
                        break;
                    case -10:
                        strData.AppendFormat("<dd>{0}</dd>", "未生效");
                        break;
                    case 10:
                        strData.AppendFormat("<dd>{0}</dd>", "生效");
                        break;
                    case -40:
                        strData.AppendFormat("<dd>{0}</dd>", "失效");
                        break;
                }
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            strData.AppendFormat("<dd><a href=\"/page/LetterOfIntent_Mgr/IntentDetail.aspx?IntentionId={1}\" target=\"_blank\">{0}</a></dd>", row["IntentionCode"].ToString(), row["IntentionId"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["BusinessType"].ToString()=="10"?"出售":"出租");
            strData.AppendFormat("<dd>{0}</dd>", row["BelongCompany"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["business"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["BelongDepart"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["BelongEmp"].ToString());
            if (!string.IsNullOrEmpty(row["DeliverTime"].ToString()))
            {
                dtTempTime = (DateTime)row["DeliverTime"];
                strData.AppendFormat("<dd>{0}</dd>", dtTempTime.Year.ToString().PadLeft(4, '0') + "-" +
                                                     dtTempTime.Month.ToString().PadLeft(2, '0') + "-" +
                                                     dtTempTime.Day.ToString().PadLeft(2, '0'));
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            strData.AppendFormat("<dd>{0}</dd>", row["LastEmployee"].ToString());
            if (!string.IsNullOrEmpty(row["LastEmployeeGetTime"].ToString()))
            {
                dtTempTime = (DateTime)row["LastEmployeeGetTime"];
                strData.AppendFormat("<dd>{0}</dd>", dtTempTime.Year.ToString().PadLeft(4, '0') + "-" +
                                                     dtTempTime.Month.ToString().PadLeft(2, '0') + "-" +
                                                     dtTempTime.Day.ToString().PadLeft(2, '0'));
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            strData.AppendFormat("<dd>{0}</dd>", row["Region"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["HouseAddress"].ToString());
            if (!string.IsNullOrEmpty(row["TotalPrice"].ToString()))
            {
                strData.AppendFormat("<dd>{0}</dd>", row["TotalPrice"].ToString());
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            strData.AppendFormat("<dd>{0}</dd>", row["CustomerName_Sale"].ToString());
            strData.AppendFormat("<dd>{0}</dd>", row["CustomerName_Buy"].ToString());
            if (!string.IsNullOrEmpty(row["FirstMoney"].ToString()))
            {
                strData.AppendFormat("<dd>{0}</dd>", row["FirstMoney"].ToString());
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            if (!string.IsNullOrEmpty(row["TotalMoney"].ToString()))
            {
                strData.AppendFormat("<dd>{0}</dd>", row["TotalMoney"].ToString());
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            if (!string.IsNullOrEmpty(row["GetedMoney"].ToString()))
            {
                strData.AppendFormat("<dd>{0}</dd>", row["GetedMoney"].ToString());
                strData.AppendFormat("<dd>{0}</dd>", row["DeliveredMoney"].ToString().Length>0?row["DeliveredMoney"].ToString():"0");
                strData.AppendFormat("<dd>{0}</dd>", (decimal.Parse(row["GetedMoney"].ToString()) - decimal.Parse(row["DeliveredMoney"].ToString().Length > 0 ? row["DeliveredMoney"].ToString() : "0")).ToString());
            }
            else
            {
                strData.Append("<dd></dd>");
                strData.Append("<dd></dd>");
                strData.Append("<dd></dd>");
            }
            
            if (!string.IsNullOrEmpty(row["bContracted"].ToString()))
            {
                if (bool.Parse(row["bContracted"].ToString()) == true)
                {
                    strData.AppendFormat("<dd>{0}</dd>", "是");
                }
                else
                {
                    strData.AppendFormat("<dd>{0}</dd>", "否");
                }
            }
            else
            {
                strData.Append("<dd></dd>");
            }
            strData.AppendFormat("<dd>{0}</dd>", row["ContractCode"].ToString());
            if (!string.IsNullOrEmpty(row["ChangeTime"].ToString()))
            {
                dtTempTime = (DateTime)row["ChangeTime"];
                strData.AppendFormat("<dd>{0}</dd>", dtTempTime.Year.ToString().PadLeft(4, '0') + "-" +
                                                     dtTempTime.Month.ToString().PadLeft(2, '0') + "-" +
                                                     dtTempTime.Day.ToString().PadLeft(2, '0'));
            }
            else
            {
                strData.Append("<dd></dd>");
            }

            strData.Append("</dl>");
        }

        stuPag.count = Convert.ToInt32(dsData.Tables[1].Rows[0][0]);
        stuPag.data = strData.ToString();
        return stuPag;
    }

    //*******************************************
    //功能概要       ：填充预审信息字段
    //参数説明       ：context 请求上下文
    //返回值説明     ：预审信息实体
    //功能詳細       ：填充预审信息字段
    //作成者         ：zou.xiaochun
    //作成日         ：2010-07-09
    //*******************************************
    private Chenxin.Lib.Business.Entity.t_Intention_BaseInfo CompleteIntention(Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entIntention, string status)
    {
        //添加预审信息
        if (status == "发放")
        {
            entIntention.CreateDate = DateTime.Now;
            entIntention.CreateEmpId = CurrentUserInfo.UserId;
            entIntention.CreateEmp = CurrentUserInfo.UserName;
            entIntention.DeliverTime = DateTime.Now;
            entIntention.Status = -200;
        }
        else if (status == "领用")
        {
            Chenxin.Lib.Business.BLL.t_Intention_BaseInfo bllIntention = new Chenxin.Lib.Business.BLL.t_Intention_BaseInfo();
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entOlIntention = bllIntention.GetModel(entIntention.IntentionId);
            entIntention.IntentionId = entOlIntention.IntentionId;
            entIntention.IntentionCode = entOlIntention.IntentionCode;
            entIntention.BusinessType = entOlIntention.BusinessType;
            entIntention.IntentionType = entOlIntention.IntentionType;
            entIntention.CreateDate = entOlIntention.CreateDate;
            entIntention.CreateEmpId = entOlIntention.CreateEmpId;
            entIntention.CreateEmp = entOlIntention.CreateEmp;
            entIntention.UpdateEmpId = CurrentUserInfo.UserId;
            entIntention.UpdateEmp = CurrentUserInfo.UserName;
            entIntention.UpdateTime = DateTime.Now;
            entIntention.BelongEmp = entOlIntention.BelongEmp;
            entIntention.BelongEmpId = entOlIntention.BelongEmpId;
            entIntention.BelongDepart = entOlIntention.BelongDepart;
            entIntention.BelongDepartId = entOlIntention.BelongDepartId;
            entIntention.BelongCompany = entOlIntention.BelongCompany;
            entIntention.BelongCompanyId = entOlIntention.BelongCompanyId;
            entIntention.BelongCityId = entOlIntention.BelongCityId;
            entIntention.BelongCityName = entOlIntention.BelongCityName;
            entIntention.DeliverTime = entOlIntention.DeliverTime;
            entIntention.Status = -100;
        }
        else if (status == "录入")
        {
            Chenxin.Lib.Business.BLL.t_Intention_BaseInfo bllIntention = new Chenxin.Lib.Business.BLL.t_Intention_BaseInfo();
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entOlIntention = bllIntention.GetModel(entIntention.IntentionId);
            entIntention.IntentionId = entOlIntention.IntentionId;
            entIntention.IntentionCode = entOlIntention.IntentionCode;
            entIntention.BusinessType = entOlIntention.BusinessType;
            entIntention.IntentionType = entOlIntention.IntentionType;
            entIntention.CreateDate = entOlIntention.CreateDate;
            entIntention.CreateEmpId = entOlIntention.CreateEmpId;
            entIntention.CreateEmp = entOlIntention.CreateEmp;
            entIntention.UpdateEmpId = CurrentUserInfo.UserId;
            entIntention.UpdateEmp = CurrentUserInfo.UserName;
            entIntention.UpdateTime = DateTime.Now;
            entIntention.DeliverTime = entOlIntention.DeliverTime;
            entIntention.DeliverTo = 0;
            entIntention.BelongEmp = entOlIntention.BelongEmp;
            entIntention.BelongEmpId = entOlIntention.BelongEmpId;
            entIntention.BelongDepart = entOlIntention.BelongDepart;
            entIntention.BelongDepartId = entOlIntention.BelongDepartId;
            entIntention.BelongCompany = entOlIntention.BelongCompany;
            entIntention.BelongCompanyId = entOlIntention.BelongCompanyId;
            entIntention.BelongCityId = entOlIntention.BelongCityId;
            entIntention.BelongCityName = entOlIntention.BelongCityName;
            entIntention.LastEmployeeId = entOlIntention.LastEmployeeId;
            entIntention.LastEmployee = entOlIntention.LastEmployee;
            entIntention.LastEmployeeGetTime = entOlIntention.LastEmployeeGetTime;
            entIntention.Status = -10;
        }
        else if (status == "开单")
        {
            Chenxin.Lib.Business.BLL.t_Intention_BaseInfo bllIntention = new Chenxin.Lib.Business.BLL.t_Intention_BaseInfo();
            Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entOlIntention = bllIntention.GetModel(entIntention.IntentionId);
            entIntention.IntentionId = entOlIntention.IntentionId;
            entIntention.IntentionCode = entOlIntention.IntentionCode;
            entIntention.BusinessType = entOlIntention.BusinessType;
            entIntention.IntentionType = entOlIntention.IntentionType;
            entIntention.CreateDate = entOlIntention.CreateDate;
            entIntention.CreateEmpId = entOlIntention.CreateEmpId;
            entIntention.CreateEmp = entOlIntention.CreateEmp;
            entIntention.UpdateEmpId = CurrentUserInfo.UserId;
            entIntention.UpdateEmp = CurrentUserInfo.UserName;
            entIntention.UpdateTime = DateTime.Now;
            entIntention.DeliverTime = entOlIntention.DeliverTime;
            entIntention.DeliverTo = entOlIntention.DeliverTo;
            entIntention.BelongEmp = entOlIntention.BelongEmp;
            entIntention.BelongEmpId = entOlIntention.BelongEmpId;
            entIntention.BelongDepart = entOlIntention.BelongDepart;
            entIntention.BelongDepartId = entOlIntention.BelongDepartId;
            entIntention.BelongCompany = entOlIntention.BelongCompany;
            entIntention.BelongCompanyId = entOlIntention.BelongCompanyId;
            entIntention.BelongCityId = entOlIntention.BelongCityId;
            entIntention.BelongCityName = entOlIntention.BelongCityName;
            entIntention.LastEmployeeId = entOlIntention.LastEmployeeId;
            entIntention.LastEmployee = entOlIntention.LastEmployee;
            entIntention.LastEmployeeGetTime = entOlIntention.LastEmployeeGetTime;
            entIntention.HouseId = entOlIntention.HouseId;
            entIntention.HouseCode = entOlIntention.HouseCode;
            entIntention.HouseAddress = entOlIntention.HouseAddress;
            entIntention.Region = entOlIntention.Region;
            entIntention.TotalPrice = entOlIntention.TotalPrice;
            entIntention.TotalMoney = entOlIntention.TotalMoney;
            if (entOlIntention.GetedMoney == null)
            {
                entOlIntention.GetedMoney = 0;
            }
            entIntention.GetedMoney += entOlIntention.GetedMoney;
            entIntention.CustomerName_Buy = entOlIntention.CustomerName_Buy;
            entIntention.CustomerName_Sale = entOlIntention.CustomerName_Sale;
            entIntention.FirstMoney = entOlIntention.FirstMoney;
            entIntention.DeliveredMoney = entOlIntention.DeliveredMoney;
            entIntention.LastContractDate = entOlIntention.LastContractDate;
            entIntention.LastDeliverMoneyDate = entOlIntention.LastDeliverMoneyDate;
            entIntention.DeliverTo = entOlIntention.DeliverTo;
            entIntention.LostItems = entOlIntention.LostItems;
            entIntention.GetAuthorizeDate = entOlIntention.GetAuthorizeDate;
            entIntention.ChangeTime = entOlIntention.ChangeTime;
            entIntention.StatusDescription = entOlIntention.StatusDescription;
            entIntention.bContracted = entOlIntention.bContracted;
            entIntention.ContractId = entOlIntention.ContractId;
            entIntention.ContractCode = entOlIntention.ContractCode;
            entIntention.Status = entOlIntention.Status;
        }
        return entIntention;
    }

    //*******************************************
    //功能概要       ：填充预审信息字段
    //参数説明       ：context 请求上下文
    //返回值説明     ：预审信息实体
    //功能詳細       ：填充预审信息字段
    //作成者         ：zou.xiaochun
    //作成日         ：2010-07-09
    //*******************************************
    private Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs CompleteDeliverLogs(Chenxin.Lib.Business.Entity.t_Intention_DeliverLogs entDeliverLogs)
    {
        entDeliverLogs.DeliverTime = DateTime.Now;
        entDeliverLogs.DeliverEmpId = CurrentUserInfo.UserId;
        entDeliverLogs.DeliverEmp = CurrentUserInfo.UserName;
        entDeliverLogs.DeliverDepartId = CurrentUserInfo.DepartId;
        entDeliverLogs.DeliverDepart = CurrentUserInfo.DepartName;
        entDeliverLogs.DeliverCompanyId = CurrentUserInfo.CompanyId;
        entDeliverLogs.DeliverCompany = CurrentUserInfo.CompanyName;
        entDeliverLogs.DeliverCityId = CurrentUserInfo.CityId;
        entDeliverLogs.DeliverCity = CurrentUserInfo.CityName;
        return entDeliverLogs;
    }

    //*******************************************
    //功能概要       ：填充预审信息字段
    //参数説明       ：context 请求上下文
    //返回值説明     ：预审信息实体
    //功能詳細       ：填充预审信息字段
    //作成者         ：zou.xiaochun
    //作成日         ：2010-07-09
    //*******************************************
    private Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo CompleteBillGeted(Chenxin.Lib.Business.Entity.t_Intention_BillGetedInfo entBillGeted,int inorout)
    {
        Chenxin.Lib.Business.BLL.t_Intention_BaseInfo bllBaseInfo = new t_Intention_BaseInfo();
        Chenxin.Lib.Business.Entity.t_Intention_BaseInfo entOldBaseInfo = new Chenxin.Lib.Business.Entity.t_Intention_BaseInfo();
        entOldBaseInfo = bllBaseInfo.GetModel(entBillGeted.IntentionId);
        
        string type = string.Empty;
        if (entBillGeted.AccountType == 10)
        {
            type = "g";
        }
        else
        {
            type = "s";
        }
        if (inorout==0)
            type = "p";

        entBillGeted.BillId = Guid.NewGuid();
        entBillGeted.BillCode = Chenxin.Lib.Business.DAL.AutoCode_BillControllerInfo.GetCodeByType(entOldBaseInfo.BelongCompanyId,type,DateTime.Now.Year.ToString().Substring(2,2));

        Chenxin.Lib.Hr.Entity.Hr_DepartmentInfo departinfo = Chenxin.Lib.Hr.DAL.Hr_DepartmentInfo.GetModel(entBillGeted.GetedDepartId);
        entBillGeted.GetedCityId = departinfo.CityId;
        entBillGeted.GetedCity = departinfo.City;
        entBillGeted.GetedCompanyId = departinfo.CompanyId;
        entBillGeted.GetedCompany = departinfo.CompanyName;
        entBillGeted.Addtime = DateTime.Now;
        entBillGeted.AddEmployeeId = CurrentUserInfo.UserId;
        entBillGeted.AddEmployee = CurrentUserInfo.UserName;
        entBillGeted.AddDepartId = CurrentUserInfo.DepartId;
        entBillGeted.AddDepart = CurrentUserInfo.DepartName;
        entBillGeted.IsConfirmed = false;
        entBillGeted.Status = 1;
        entBillGeted.InOrOut = inorout;

        return entBillGeted;
    }
    
}